package com.lagou.hint;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: hint强制路由
 * @date 2022/9/13 20:33
 */
public class MyHintShardingAlgorithm implements HintShardingAlgorithm<Long> {
    @Override
    public Collection<String> doSharding(Collection<String> availableTargetNames, HintShardingValue<Long> shardingValue) {
        Collection<String> result = new ArrayList<String>();
        for (String availableTargetName : availableTargetNames) {
            Collection<Long> values = shardingValue.getValues();
            for (Long value : shardingValue.getValues()) {
                if(availableTargetName.endsWith(String.valueOf(value%2))){
                    result.add(availableTargetName);
                }
            }

        }
        return result;
    }
}
